package com.example;


import java.util.ArrayList;
import java.util.List;

public class GreenDaoGenerator {


    public static void main(String[] args) throws Exception {

        /*Schema schema = new Schema(1, "cn.player.db");
        Entity videoInfoEntity = schema.addEntity("VideoInfo");
        Property idProperty = videoInfoEntity.addIdProperty().getProperty();
        videoInfoEntity.addIntProperty("vid");
        videoInfoEntity.addStringProperty("title");
        videoInfoEntity.addStringProperty("url");

        File outputDir = new File("app/src/main/java");
        outputDir.mkdirs();

        File daoFile = new File(outputDir, "cn/player/db/" + videoInfoEntity.getClassName() + "Dao.java");
        daoFile.delete();

        System.out.println("idProperty.getConstraints(): " + idProperty.getConstraints());

        DaoGenerator daoGenerator = new DaoGenerator();
        daoGenerator.generateAll(schema, outputDir.getPath());*/

        double[] dooubleNums = {3.11, 9.01, 49.5, 33.11, 77.11, 97.11, 103.11, 133.11, 140.0, 143.93, 173.11, 933.11, 973.11, 993.11, 1133.11, 1773.11, 1933.11, 1973.11, 1993.11};
        int[] intNumbs = {5, 6, 10, 15, 20, 24, 60, 90, 91, 140, 150, 160, 170, 180, 190, 200, 210, 270,280,290,300,350,500,650,1000};
        int[] intNumbs2 = {9, 44,123, 130,140, 150};

        for (double num : dooubleNums) {
            System.out.println("isIntegerNum() = " + isIntegerNum(num) + "," + num + ": " + calculateShortCutDoubleNum(num, "￥"));
        }
        System.out.println("**************************************************");
        for (int num : intNumbs2) {
            System.out.println("isIntegerNum() = " + isIntegerNum(num) + "," + num + ": " + calculateShortCutIntNum(num, "￥"));
        }
    }

    public static List<String> calculateShortCutNum(double num, String prefix) {
        if (isIntegerNum(num)) {
            return calculateShortCutIntNum((int) num, prefix);
        } else {
            return calculateShortCutDoubleNum(num, prefix);
        }
    }

    public static boolean isIntegerNum(double num) {
        int intNum = (int) num;
        return intNum == num;
    }

    public static List<String> calculateShortCutDoubleNum(double num, String prefix) {
        int floorNum = (int) Math.floor(num);

        int remainder_10 = floorNum % 10;
        int remainder_100 = floorNum % 100;

        int shortCutNum1 = (int) Math.ceil(num);
        int shortCutNum2 = floorNum - remainder_10 + 10;
        int shortCutNum4 = floorNum - remainder_100 + 100;
        int shortCutNum3 = shortCutNum4 - 50;
        List<String> results = new ArrayList<>();
        results.add(prefix + shortCutNum1);
        if(shortCutNum2 > shortCutNum1){
            results.add(prefix + shortCutNum2);
        }
        if (shortCutNum3 > shortCutNum2) {
            results.add(prefix + shortCutNum3 + "");
        }
        if (shortCutNum4 > shortCutNum2) {
            results.add(prefix + shortCutNum4);
        }
        return results;
    }

    public static List<String> calculateShortCutIntNum(int num, String prefix) {
        int floorNum = num;
        int remainder_10 = floorNum % 10;
        int remainder_100 = floorNum % 100;

        int shortCutNum1 = floorNum - remainder_10 + 10;
        int shortCutNum3 = floorNum - remainder_100 + 100;
        int shortCutNum2 = shortCutNum3 - 50;
        List<String> results = new ArrayList<>();
        if (remainder_100 == 0) {
            return results;
        }
        if (shortCutNum1 % 100 == 0) {
            results.add(prefix + shortCutNum1);
            return results;
        }
        if (remainder_10 != 0 && shortCutNum1 >= floorNum) {
            results.add(prefix + shortCutNum1);
        }
        if (remainder_100 != 0 && shortCutNum2 > floorNum && shortCutNum2 > shortCutNum1) {
            results.add(prefix + shortCutNum2);
        }

        if (remainder_100 != 0 && shortCutNum3 > shortCutNum2 && shortCutNum3 > shortCutNum1) {
            results.add(prefix + shortCutNum3);
        }
        return results;
    }

}
